<template>
  <div class="user-feedback">
    <div class="title">产品需求</div>
    <el-form :model="feedback" ref="form" size="medium">
      <el-form-item
        ><div class="item">
          <div class="tit"><i>*</i> 手机号码：</div>
          <div class="input">
            <el-input
              placeholder="请输入"
              style="width: 260px"
              v-model="feedback.phone"
            ></el-input>
          </div>
        </div>
      </el-form-item>
      <el-form-item
        ><div class="item">
          <div class="tit"><i>*</i> 投诉/建议描述：</div>
          <div class="input">
            <el-input
              style="width: 475px"
              :rows="6"
              placeholder="必填"
              type="textarea"
              v-model="feedback.describe"
            ></el-input>
          </div>
        </div>
      </el-form-item>
      <el-form-item
        ><div class="item">
          <div class="tit">上传凭证：</div>
          <div class="input image-box">
            <div
              class="image"
              v-for="(item, index) in feedback.voucher"
              :key="index"
            ></div>
            <div class="add" v-if="feedback.voucher.length < 9">
              +<span
                >上传照片<br />{{ feedback.voucher.length }}最多上传9张</span
              >
            </div>
          </div>
        </div>
      </el-form-item>
    </el-form>
    <el-button class="buttons" type="primary" @click="sendFeedback"
      >提交申请</el-button
    >
  </div>
</template>

<script>
import api from "@/api";
import { mapState } from "vuex";
import verify from "@/libs/util.verify";

export default {
  name: "UserData",
  computed: {
    ...mapState("user", ["userinfo"]),
  },
  data() {
    return {
      feedback: {
        phone: "",
        describe: "",
        voucher: [],
      },
    };
  },
  methods: {
    async sendFeedback() {
      if (!verify.isPhone(this.feedback.phone))
        return this.$message.error("请输入正确的手机号码");

      if (verify.isEmpty(this.feedback.describe))
        return this.$message.error("需求内容不能为空");

      let loading = this.loadingMsg();
      await api.PRODUCT_DEMAND(this.feedback);
      this.feedback = {
        phone: "",
        describe: "",
        voucher: [],
      };
      this.$message.success("提交成功");
      loading.close();
    },
  },
};
</script>

<style lang="scss" scoped>
.user-feedback {
  border: 1px solid #dedede;
  padding: 20px;
  .title {
    margin-bottom: 28px;
    font-size: 20px;
    font-weight: 600;
    color: #333333;
    line-height: 28px;
  }
  .item {
    display: flex;
    .tit {
      width: 118px;
      font-size: 14px;
      color: #333333;
      line-height: 36px;
      margin-right: 12px;
      i {
        color: red;
      }
    }
    .input {
      &.update {
        width: 96px;
        flex-direction: column;
        display: flex;
        justify-content: center;
        align-items: center;
        .image {
          width: 70px;
          height: 70px;
          margin: 0 auto 10px;
          background: #ffffff;
          border: 1px solid #c7c7c7;
          border-radius: 50%;
          overflow: hidden;
        }
        .button {
        }
      }
    }
  }
  .buttons {
    width: 160px;
    height: 44px;
  }
  .image-box {
    width: 426px;
    display: flex;
    flex-wrap: wrap;
    .image,
    .add {
      cursor: pointer;
      margin: 0 20px 20px 0;
      width: 120px;
      height: 120px;
      background: #ffffff;
      border-radius: 5px;
      border: 1px solid #dedede;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
      color: #999999;
      font-size: 50px;
      span {
        margin-top: 13px;
        line-height: 20px;
        font-size: 14px;
      }
    }
  }
}
</style>
